<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <body>

        <ui:composition template="./adminTemplate.xhtml">

            <ui:define name="title">
                List Admin
            </ui:define>

            <ui:define name="contain">
                <h:form id="form">
                    <h2 class="ico_mug">
                        List Admin
                        <p:button value="Add Admin" styleClass="button-add" outcome="addAdmin.xhtml"/>
                    </h2>
                    <p:messages autoUpdate="true" showDetail="true" showSummary="true"></p:messages>
                    <p:dataTable id="table-item" var="ad" value="#{adminController.listAdmin}" 
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="10,15,20" paginator="true" rows="10">  
                        <p:column style="text-align: center">  
                            <f:facet name="header">  
                                ID 
                            </f:facet>  
                            <h:outputText value="#{ad.id}" />  
                        </p:column>  
                        <p:column>  
                            <f:facet name="header">  
                                Username 
                            </f:facet>  
                            <h:outputText value="#{ad.username}" />  
                        </p:column>                              
                        <p:column>  
                            <f:facet name="header">  
                                Password
                            </f:facet>  
                            <h:outputText value="#{ad.password}" />  
                        </p:column>
                        <p:column>  
                            <f:facet name="header">  
                                Fullname  
                            </f:facet>  
                            <h:outputText value="#{ad.fullname}"/>
                        </p:column>                    
                        <p:column>  
                            <f:facet name="header">  
                                Address 
                            </f:facet>  
                            <h:outputText value="#{ad.address}" />  
                        </p:column> 
                        <p:column>  
                            <f:facet name="header">  
                                Phone 
                            </f:facet>  
                            <h:outputText value="#{ad.phone}"/>
                        </p:column>
                        <p:column style="text-align: center;width: 60px">  
                            <f:facet name="header">  
                                Action  
                            </f:facet>  
                            <p:commandLink action="#{adminController.selectedID(ad.id)}" oncomplete="confirmation.show()">
                                <img src="img/delete.png" alt="delete"/>
                            </p:commandLink>

                            <h:commandLink actionListener="#{adminBean.edit(ad)}">
                                <img src="img/edit.png" alt="edit"/>
                            </h:commandLink>
                        </p:column> 
                    </p:dataTable>
                    <p:confirmDialog id="confirmation" message="Are you sure to delete this Admin?"  
                                     header="Delete Admin" severity="alert" widgetVar="confirmation" > 
                        <p:commandButton value="Yes Sure" update=":form:table-item" oncomplete="confirmation.hide()"  
                                         actionListener="#{adminController.deleteAdmin()}" />  
                        <p:commandButton value="Not Yet" onclick="confirmation.hide()" type="button" />   
                    </p:confirmDialog>

                    <p:fieldset legend="Edit Information">
                        <table cellpadding="5">
                            <tbody>
                                <tr>
                                    <td style="width: 80px"><h:outputLabel value="ID:"/></td>
                                    <td style="width: 200px"><p:inputText value="#{adminBean.id}"/></td>
                                    <td style="width: 80px"><h:outputLabel value="Address:"/></td>
                                    <td><p:inputText id="address" value="#{adminBean.address}"/> </td>
                                </tr>
                                <tr>
                                    <td><h:outputLabel value="Username:"/></td>
                                    <td><p:inputText id="username" value="#{adminBean.username}"/></td>
                                    <td><h:outputLabel value="Fullname:"/></td>
                                    <td><p:inputText id="fullname" value="#{adminBean.fullname}"/></td>

                                </tr>
                                <tr>
                                    <td><h:outputLabel value="Password:"/></td>
                                    <td><p:inputText id="password" value="#{adminBean.password}"/>   </td>
                                    <td><h:outputLabel value="Phone:"/></td>
                                    <td><p:inputText id="phone" value="#{adminBean.phone}"/></td>

                                </tr>
                                <tr>
                                    <td></td>
                                    <td><p:commandButton ajax="false" value="Update" actionListener="#{adminController.editAdmin(adminBean.id, adminBean.username, adminBean.password, adminBean.fullname, adminBean.address, adminBean.phone)}"/>
                                    </td>
                                </tr>                                
                            </tbody>
                        </table>
                    </p:fieldset>
                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>
